<?php 
if(KT!='KhiThe') exit;
class manufacturers_controller extends manufacturers_model{
		
	public function __construct(){
		global $lang;
		$this->lang = $lang;
		parent::__construct();
		parent::addObject('khithe_template');
		parent::addObject('khithe_request');
		parent::addObject('khithe_string');
	}
	
	public function index_action()
	{
		$resultHtml = NULL;
		$strHtmlContent = $this->khithe_display('index');
		$arrBlockHtml = $this->khithe_getBlockHtml($strHtmlContent);
		
		$resultManufac = parent::getManufacturers('0');

		while( $rowManufac = mysql_fetch_assoc($resultManufac) )
		{
			$arrManufac = array(
				"cell_ID"=>$rowManufac['ID'],
				"cell_1"=>'<input name="delId[]" type="checkbox" value="'.$rowManufac['ID'].'" />',
				"cell_2"=>"HSX_".$rowManufac['ID'],
				"cell_3"=>$rowManufac['Manufacturer'],
				"cell_4"=>$this->lang['cat-order'].' '.$rowManufac['Order'],
				"cell_5"=>$rowManufac['Status']=='true'?$this->lang['enabled']:$this->lang['disabled'],
				"class_cell"=>$rowManufac['Status']=='true'?"cell_groupitem1":"cell_groupitem_ex1",
				
			);
			$resultHtml .= $this->khithe_assign($arrBlockHtml['manufacturers'],$arrManufac);
			
		} mysql_free_result($resultManufac);
		
		$strHtmlContent = $this->khithe_assignBlock($strHtmlContent, array('htmlCat'=>$resultHtml));
		$strHtmlContent = $this->khithe_assign($strHtmlContent, $this->lang);
		return $strHtmlContent;		
	}
	
	public function add_action()
	{
		if($_GET['iframe']=='true')
		{
			$this->lang['txt_value'] ='';
			$this->lang['active'] ='add';
			$this->lang['ManufacturersID'] ='';
			$this->lang['val_Order'] ='';
			$this->lang['titlePageEditor'] = $this->lang['addTitle'];
			$strHtmlContent = $this->khithe_display('editor');
			$strHtmlContent = $this->khithe_assign($strHtmlContent, $this->lang);
			return $strHtmlContent;
		}
	}
	
	public function edit_action()
	{
		if($_GET['iframe']=='true')
		{
			$resultManufac = parent::getManufac($this->valUrl(1));
			$rowManufac = mysql_fetch_assoc($resultManufac);
			$strHtmlContent = $this->khithe_display('editor');
			$this->lang['titlePageEditor'] = $this->lang['editTitle'];
			$this->lang['txt_value'] = $rowManufac['Manufacturer'];
			$this->lang['active'] ='edit';
			$this->lang['ManufacturersID'] =$rowManufac['ID'];
			$this->lang['val_Order'] =$rowManufac['Order'];
			$strHtmlContent = $this->khithe_assign($strHtmlContent, $this->lang);
			return $strHtmlContent;
		}
	}
	
	public function index_ajax_action()
	{
		
		switch ($this->valUrl(1))
		{
			case 'open':
				$arr = explode(',',$this->valUrl(2));
				foreach ( $arr as $ID ){
					$done = parent::setCheckedManufac($ID,'true');
				}
			break;
			
			case 'close':
				$arr = explode(',',$this->valUrl(2));
				foreach ( $arr as $ID ){
					$done = parent::setCheckedManufac($ID,'false');
					if($done){
						$getCat = parent::getManufacturers($ID);
						while( $row = mysql_fetch_assoc($getCat) )
						{
							parent::setCheckedManufac($row['ID'],'false');
						} mysql_free_result($getCat);
					}
				}
			break;
			
			case 'del':
				$arr = explode(',',$this->valUrl(2));
				foreach ( $arr as $ID ){
					$done = parent::delCheckedManufac($ID);
					if($done){
						$getDelCat = parent::getManufacturers($ID);
						while( $row = mysql_fetch_assoc($getDelCat) )
						{
							parent::delCheckedManufac($row['ID']);
						} mysql_free_result($getDelCat);
					}
				}
			break;
			
			case 'edit':
				$done = parent::updateInsertCat($_POST);
			break;
			
			
			case 'add':
				$done = parent::updateInsertCat($_POST);
			break;
			
		}
		if($this->valUrl(1)!=''&&isset($done)){
			return $this->index_action();
			
		}else{
			return 'notOK';
		}
	}


}
?>